import re

a = 'A8C3721D86'


def convert(val):
    matched = val.group()
    if int(matched) >= 6:
        return '9'
    else:
        return '0'


r = re.sub('\d', convert, a)

print(r)
